/*
 * Copyright (c) 2019. Dxxld@qq.com. All rights reserved.
 */

package com.wauil.keenote.algorithm;

/**
 * @Description: 插入排序
 * @Author: kee
 * @Email: dxxld@qq.com
 * @Date: 2019/12/20 15:05
 * @Version: 1.0
 */
public class InsertSort {
    public void sort(int[] array) {
        for (int i = 0; i < array.length; i++) {
            int temp = array[i];
            int empty = i;
            for (int j = i; j > 0; j--) {
                if (array[j - 1] > temp) {
                    array[j] = array[j - 1];
                    empty = j - 1;
                } else {
                    break;
                }
            }
            array[empty] = temp;
        }
    }
}
